<!doctype html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="web_socket.min.js"></script>
    <script src="angular.min.js"></script>
</head>
<body ng-controller="appCtrl">

Hello world
<script>
    var app = angular.module('app', []);
    app.controller('appCtrl', ['$scope', function ($scope) {
//        $scope.getContextPath = function () {
//            var pathName = document.location.pathname;
//            var index = pathName.substr(1).indexOf("/");
//            var result = pathName.substr(0, index + 1);
//            return result;
//        }
//        var ctx = window.location.origin + $scope.getContextPath();
        if (window['WebSocket']) {
            $scope.websocket = new WebSocket("ws://localhost:8080/websocket");
        } else {
            $scope.websocket = new SockJS("http://localhost:8080/websocket/socketjs");
        }
        $scope.websocket.onopen = function (event) {
            console.log("websocket开启:" + event);
        }
        $scope.websocket.onclose = function (event) {
            console.log("websocket关闭:" + event);
        };
        $scope.websocket.onmessage = function (event) {
//            console.log("onMessage:" + event);
            console.log(event.data);
        }
    }]);
</script>
</body>
</html>